﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Project.MODEL;
using Project.BLL;
using Project.BLL.System;
using Newtonsoft.Json;

namespace Project.UI.Areas.System.Controllers
{
    public class UserController : Controller
    {
        EmployeeBll bll = new EmployeeBll();

        // GET: System/User
        public ActionResult Employee()
        {
            return View();
        }

        public ActionResult PersonalDetails()
        {
            Employee emp =  Session["user"]as Employee;
            return View(emp);
        }

        public ActionResult GetEmployeeList(int page, int limit)
        {
            string name = Request.Params["name"];
            var list = bll.GetEmployeeList(page, limit, name);
            return Content(list, "Application/Json");
        }

        [HttpPost]
        public ActionResult AddEmployee(Employee emp)
        {
            //设置操作人和时间
            emp.cmdEmID = int.Parse(Session["uid"].ToString());
            emp.lastTime = DateTime.Now;
            var data = bll.AddEmployee(emp);
            return Content(data, "Application/Json");
        }

        [HttpPost]
        public ActionResult UpdateEmployee(Employee emp)
        {
            //设置操作人和时间
            emp.cmdEmID = int.Parse(Session["uid"].ToString());
            emp.lastTime = DateTime.Now;

            return Content(bll.UpdateEmployee(emp), "Application/Json");
        }

        [HttpPost]
        public ActionResult DeleteAll(string ids)
        {
            return Content(bll.DeleteAll(ids), "Application/Json");
        }

        [HttpPost]
        public ActionResult ChangePassword(string pwd,string newpwd)
        {
            int uid = int.Parse(Session["uid"].ToString());
            return Content(bll.ChangePassword(uid, pwd, newpwd), "Application/Json");
        }

        [HttpPost]
        public ActionResult ChangeHeadImg(string imgpath)
        {
            int uid = int.Parse(Session["uid"].ToString());
            return Content(bll.ChangeHeadImg(uid, imgpath), "Application/Json");
        }
    }
}